<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="./css/注册.css" />
    <script src="./js/axios.min.js"></script>
  </head>
  <body>
    <div class="box1">
      <img src="img/jd狗.png" alt="" />
      <h2>欢迎注册</h2>
      <span>已有账号？<a href="登录.html">请登录 ></a></span>
    </div>
    <div class="box2">
      <input type="text" placeholder="请输入注册账号" class="ipt1" />
      <input type="text" placeholder="请输入密码" class="ipt1" />
      <input type="button" value="注册" class="btn" />
    </div>
    <script>
      let ipt = document.querySelectorAll("input");
      ipt[2].onclick = function () {
        let uname = ipt[0].value;
        let pword = ipt[1].value;
        let API = "http://jx.xuzhixiang.top/ap/api/reg.php";
        axios
          .get(API, { params: { username: uname, password: pword } })
          .then((res) => {
            let r = res.data;
            console.log(r);
            if (r.code == 1) {
              alert(r.msg);
              location.href = "./登录.html";
            } else {
              alert(r.msg + "请重新注册!");
            }
          });
      };
    </script>
  </body>
</html>
